package com.esunny.resourcevisualization.controller;

import com.esunny.resourcevisualization.domain.response.ReturnStructure;
import com.esunny.resourcevisualization.service.GroupResourceService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * @version 1.0.0.0
 * @ClassName GroupResourceController
 * @Description 组资源获取接口
 * @Author baochencong
 * @Date 2020/11/5 9:56
 */
@Controller
@RequestMapping("/resource")
public class GroupResourceController {

    @Resource
    private GroupResourceService groupResourceService;

    /**
     * 通过用户组名和资源类别英文名获取组实体资源
     *
     * @param userGroupName 用户组名
     * @param name          资源类别英文名
     * @return 该用户组下该资源类别的实体资源列表
     */
    @ResponseBody
    @GetMapping("/getGroupResourceByEntityIdAndName/{userGroupName}/{name}")
    public ReturnStructure getGroupResourceByEntityIdAndName(@PathVariable("userGroupName") String userGroupName, @PathVariable("name") String name) {
        if (StringUtils.isBlank(userGroupName) || StringUtils.isBlank(name)) {
            return ReturnStructure.NOT_FOUND();
        }
        return ReturnStructure.SUCCESS("获取组资源成功", groupResourceService.getGroupResourceListByUserGroupNameAndResourceTypeName(userGroupName, name));
    }

}
